<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

/**
 * 分类控制器
 * Class CategoryController
 * @package Home\Controller
 */
class CategoryController extends HomeController {

    public function __construct(){
        parent::__construct();
//        // 导航列表
//        $channelList = D('channel')->limit(4)->lists();
//        $this->assign('channelList', $channelList);
        // 树形分类
        $cateTree   =   D("Category")->getTree();
        $this->assign('cateTree', $cateTree);
        //var_dump($cateTree);
        $this->assign('notCate', 1);    // 不展开分类导航
    }

    /* 文档模型频道页 */
	public function index(){
        $this->display();
	}


    /**
     * 文章分类数据
     */
    public function lists(){

        $cateId = I('cateid');
        $currCateTree   =   D("Category")->getTree($cateId, true, array('allow_publish'=>array('gt',0)));
        // 有子集分类
        //var_dump($currCateTree);
        $item=array();
        if($currCateTree['pid']=='1'){
            $item['url']=U('Order/goods?type=1');
            $item['title']="HR沙龙";
        }else if($currCateTree['pid']=='50'){
            $item['url']=U('Order/goods?type=2');
            $item['title']="劳动法沙龙";
        }else if($currCateTree['pid']=='51'){
            $item['url']=U('Order/goods?type=3');
            $item['title']="职涯沙龙";
        }
        $this->assign('item', $item);
        if($currCateTree['_child']){
            $cateTree = $currCateTree['_child'];
            do{
                $cate = current($cateTree);
                $cateIdStr = $this->getTreeToCateIdStr($cate);
                if($cateIdStr){
//                    unset($cate['_child']);
                    $cateList[$cate['name']] = $cate;    // 分类数据
                    $cateList[$cate['name']]['docList'] = D('Document')->limit(10)->lists($cateIdStr, 'id desc');     // 按时间排序
                }
            }while(next($cateTree) && $cate = current($cateTree));  // 读取下一级分类
            $this->assign('cateList', $cateList);
            unset($currCateTree['_child']);
            $this->assign('cate', $currCateTree);   // 当前分类信息
            $this->display('lists');
        }else{  // 没有子集分类
            $cate = $currCateTree;
            $cate['docList'] = D('Document')->lists($cate['id'], 'id desc');     // 按时间排序
            $this->assign('cate', $cate);   // 当前分类信息
            $this->display('list');
        }
    }

}
